package com.example.service;

import com.example.mapper.JobIntentionMapper;
import com.example.mapper.JobRecruiterMapper;
import com.example.mapper.JobSeekerMapper;
import com.example.mapper.PostMapper;
import com.example.pojo.dto.IntentionDTO;
import com.example.pojo.dto.JobIntentionDTO;
import com.example.pojo.entity.JobIntention;
import com.example.pojo.entity.JobSeeker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 本文来演示
 *
 * @author 赵建云
 * @create 2023/10/13
 */
@Service
public class JobIntentionServiceImpl implements JobIntentionService{
    @Autowired
    private JobIntentionMapper jobIntentionMapper;
    @Autowired
    private PostMapper postMapper;
    @Autowired
    private JobRecruiterMapper jobRecruiterMapper;

    @Override
    public List<String> searchHope(Integer jsId) {
        List<String> list = jobIntentionMapper.searchHope(jsId);
        return list;
    }

    @Override
    public int saveOrUpdateHope(JobIntentionDTO jobIntentionDTO) {
        if (jobIntentionDTO.getId()==null){
            JobIntention jobIntention = new JobIntention();
            jobIntention.setCity(jobIntentionDTO.getCity());
            jobIntention.setPosition(jobIntentionDTO.getPosition());
            jobIntention.setProfession(jobIntentionDTO.getProfession());
            String salary = jobIntentionDTO.getPayFloor();
            salary = salary.replace("k","");
            int salaryFloor = Integer.parseInt(salary);
            int payFloor =  salaryFloor*1000;
            String salary2 = jobIntentionDTO.getPayUpper();
            salary2 = salary2.replace("k","");
            int salaryUpper = Integer.parseInt(salary2);
            int payUpper = salaryUpper*1000;
            jobIntention.setPayFloor(payFloor);
            jobIntention.setPayUpper(payUpper);
            jobIntention.setJsId(jobIntentionDTO.getJsId());
            int count = jobIntentionMapper.saveHope(jobIntention);
            return 0;
        }else {
            JobIntention jobIntention = new JobIntention();
            jobIntention.setId(jobIntentionDTO.getId());
            jobIntention.setCity(jobIntentionDTO.getCity());
            jobIntention.setPosition(jobIntentionDTO.getPosition());
            jobIntention.setProfession(jobIntentionDTO.getProfession());
            String salary = jobIntentionDTO.getPayFloor();
            salary = salary.replace("k","");
            int salaryFloor = Integer.parseInt(salary);
            int payFloor =  salaryFloor*1000;
            String salary2 = jobIntentionDTO.getPayUpper();
            salary2 = salary2.replace("k","");
            int salaryUpper = Integer.parseInt(salary2);
            int payUpper = salaryUpper*1000;
            jobIntention.setPayFloor(payFloor);
            jobIntention.setPayUpper(payUpper);
            int count = jobIntentionMapper.updateHope(jobIntention);
            return 1;
        }
    }

    @Override
    public List<JobIntentionDTO> findHopes(Integer jsId) {
        List<JobIntentionDTO> jobIntentionDTOS = new ArrayList<>();
        List<JobIntention> jobIntentionList = jobIntentionMapper.findHopes(jsId);
        if (null!=jobIntentionList&&jobIntentionList.size()>0){
            for (JobIntention jobIntention : jobIntentionList) {
                JobIntentionDTO jobIntentionDTO = new JobIntentionDTO();
                jobIntentionDTO.setId(jobIntention.getId());
                jobIntentionDTO.setCity(jobIntention.getCity());
                jobIntentionDTO.setPosition(jobIntention.getPosition());
                jobIntentionDTO.setProfession(jobIntention.getProfession());
                jobIntentionDTO.setPayFloor(jobIntention.getPayFloor()/1000+"k");
                jobIntentionDTO.setPayUpper(jobIntention.getPayUpper()/1000+"k");
                jobIntentionDTOS.add(jobIntentionDTO);
            }
        }
        return jobIntentionDTOS;
    }


}
